<?php

/**
 *      [Discuz!] (C)2001-2099 Comsenz Inc.
 *      This is NOT a freeware, use is subject to license terms
 *
 *      $Id: table_dzapp_base_jssdk.php 33234 2016-06-18 15:44:05Z mpage $
 */

if(!defined('IN_DISCUZ')) {
	exit('Access Denied');
}

class table_dzapp_base_jssdk extends discuz_table {

	public function __construct() {
		$this->_table = 'dzapp_base_jssdk';
		$this->_pk    = 'jssdk_id';

		parent::__construct();
	}

	public function fetch_by_search($param) {
		return DB::fetch_first('SELECT * FROM %t %i', array($this->_table, $this->wheresql($param)));
	}

	public function count_by_search($param) {
		return DB::result_first('SELECT COUNT(*) FROM %t %i', array($this->_table, $this->wheresql($param)));
	}
	
	public function fetch_all_by_search($param, $start = 0, $limit = 0, $order = 'jssdk_id', $sort = 'DESC', $keyfield = '') {
		$ordersql =  $order ? ' ORDER BY '.DB::order($order, $sort) : '';
		return DB::fetch_all('SELECT * FROM %t %i %i '.DB::limit($start, $limit), array($this->_table, $this->wheresql($param), $ordersql), $keyfield);
	}
	
	public function wheresql($param) {
		foreach($param as $value) {
			if($value[1]) {
				if($value[0] == 'sql') {
					$wherearr[] = $value[1];
				} else {
					$wherearr[] = DB::field($value[0], is_array($value[1]) ? $value[1] : $value[3].$value[1].$value[4], $value[2] ? $value[2] : '=');
				}
			}
		}
		$wheresql = $wherearr ? 'WHERE '.implode(' AND ', $wherearr) : '';
		return $wheresql;
	}

	public function increase($id, $setarr) {
		$sql = array();
		foreach($setarr as $key => $value) {
			$sql[] = "`$key`=`$key`+'$value'";
		}
		return DB::query('UPDATE %t SET %i WHERE %i', array($this->_table, implode(',', $sql), DB::field($this->_pk, $id)));
	}
}

?>